﻿-var realstatuses = (from ws in statuses where ws.Id > 0 select ws).ToList()
-var newStatus = new Status()
-newStatus.Name = "Новая заявка"; newStatus.Id = 0; newStatus.Image24="default/new24.gif"; statuses.Insert(0,newStatus)
%table.data{width="100%"}
  %tr
    %th{width="20%"} Из статуса
    %th{width="80%"} В статус
  -foreach(var status in statuses)
    -var tostatuses = (from m in matrix where ((status.Id>0 && m.FromStatusId==status.Id) || (status.Id == 0 && m.FromStatusId==null)) orderby m.ToStatus.SortOrder select m.ToStatusId).Distinct()
    %tr
      %td.fromstatus{width="15%"}
        %img{src=String.Format("img/statuses/{0}",status.Image24),width="24",height="24",title=status.Name}
        %span=status.Name
      %td.tostatus
        -foreach(var ts in realstatuses)
          -if(ts.Id==status.Id) continue
          %div{class="row padded5"+(tostatuses.Contains(ts.Id)?"":" hidden new")}
            %table
              %tr
                %td{width="25%"}
                  %img.icon16{src=String.Format("img/statuses/{0}",ts.Image16),title=ts.Name}
                  %span=ts.Name
                %td{width="75%"}
                  -var tspermissions = (from m in matrix where m.ToStatusId == ts.Id && ((status.Id>0 && m.FromStatusId==status.Id) || (status.Id == 0 && m.FromStatusId==null)) select m.PermissionId.Value).ToArray()
                  -string selectid = string.Format("rule_{0}_{1}",status.Id,ts.Id)
                  %div
                    =HTMLHelper.MultipleSelect(selectid,permissions,"name","id",tspermissions,"mspermissions",false)
        -if(!status.IsFinal)        
          .padded5.bluebg
            %a.button{href="#",onclick="$(this).parents('.tostatus').find('.row.new.hidden').show();$(this).hide(); return false"} Создать переход
        -else
          .padded5
            %span.middle Конечный статус
.spacer5
